<include file="public@header"/>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('CourseSchedule/adjustSchedule')}">调课列表</a></li>
        <li class="active"><a href="{:url('CourseSchedule/add')}">添加</a></li>
    </ul>
    <div class="row margin-top-20">
        <div class="col-md-10 col-md-offset-2">
            <form action="{:url('CourseSchedule/addPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
                <div class="row">
                    <div class="col-md-9">
                        <table class="table table-bordered chase_classroom_table">
                            <tr>
                                <th>学校<span class="form-required">*</span></th>
                                <td>
                                    <select class="form-control" name="school_id" id="school_id" style="width:240px;">
                                        <option value='0'>--- 请选择 ---</option>
                                        <notempty name="schools">
                                            <volist name="schools" id="vo">
                                                <if condition="isset($param.school_id) && $param.school_id == $vo.id">
                                                    <option value="{$vo.id}" selected>{$vo.name}</option>
                                                    <else/>
                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                </if>
                                            </volist>
                                        </notempty>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>班级<span class="form-required">*</span></th>
                                <td>
                                    <select class="form-control" name="class_id" id="class_id" style="width:240px;">
                                        <option value='0'>--- 请选择 ---</option>
                                    </select>
                                </td>
                            </tr>

                            <tr>
                                <th>课程<span class="form-required">*</span></th>
                                <td>
                                    <input type="text" class="form-control col-md-4" name="course" id="course" value="" readonly>
                                </td>
                            </tr>
                            <tr>
                                <th>开始时间<span class="form-required">*</span></th>
                                <td>
                                    <input type="text" class="form-control" name="start_date" value="" autocomplete="off">
                                </td>
                            </tr>
                            <tr>
                                <th>结束时间<span class="form-required">*</span></th>
                                <td>
                                    <input type="text" class="form-control" name="end_date" value="" autocomplete="off">
                                </td>
                            </tr>
                        </table>

                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
                                <a class="btn btn-default" href="{:url('CourseSchedule/adjustSchedule')}">{:lang('BACK')}</a>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<!--ajax layer 弹窗-->
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('input[name="start_date"]').datepicker();
        $('input[name="end_date"]').datepicker();

        //筛选学校
        $('#school_id').on('change',function () {
            var sid = $(this).val();
            if(sid == 0){
                $('#class_id').empty();
                var html = '<option value=\"0\">--- 请选择 ---</option>';
                $('#class_id').html(html);
                return false;
            }
            $.ajax({
                url:"{:url('CourseSchedule/ajax_class')}",
                type:'post',
                dataType:'json',
                data:{"school_id":sid},
                success:function(jsonData){
                    $('#class_id').empty();
                    var html = '<option value=\"0\">--- 请选择 ---</option>';

                    if(jsonData.code == 1){
                        for(var i in jsonData.data){
                            html += '<option value=\"'+jsonData.data[i].id+'\">'+jsonData.data[i].name+'</option>';
                        }
                    }
                    $('#class_id').html(html);
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        });

        //通过班级筛选课程
        $('#class_id').on('change',function () {
            var cid = $(this).val();
            if(cid == 0){
                $('#course').empty();
                return false;
            }
            $.ajax({
                url:"{:url('CourseSchedule/ajax_course')}",
                type:'post',
                dataType:'json',
                data:{"class_id":cid},
                success:function(jsonData){
                    $('#course').empty();

                    if(jsonData.code == 1){
                        $('#course').val(jsonData.data.course_name);
                    }
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        });

    });

</script>

</body>
